cmake_minimum_required(VERSION 3.25)

if(WIN32)
    project(myWord VERSION 1.0.0 LANGUAGES CXX)
elseif(UNIX)
    project(myWord VERSION 1.0.0 LANGUAGES CXX)
endif()

set(CMAKE_CONFIGURATION_TYPES "Debug;RelWithDebInfo" CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#VS下全速编译(如果不是用VS要注释掉)
cmake_host_system_information(RESULT CPU_NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP${CPU_NUMBER_OF_LOGICAL_CORES}>)

#=============================INCLUSION OF Qt=============================#
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_PREFIX_PATH $ENV{QT_DIR_msvc})
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets PrintSupport)

#=========================INCLUSION OF Project Files=======================#
set(FORMS_DIR "${CMAKE_SOURCE_DIR}/forms")
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")

include_directories(${FORMS_DIR})
include_directories(${INCLUDE_DIR})
include_directories(${SOURCE_DIR})

file(GLOB_RECURSE SOURCES
    ${FORMS_DIR}/*.ui
    ${FORMS_DIR}/*.qrc
    ${INCLUDE_DIR}/*.h
    ${SOURCE_DIR}/*.cpp
)

#====================SETUP EXECTUABLE=====================#
# Enable debug logging on RELWITHDEBINFO configuration
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
    $<$<CONFIG:RELWITHDEBINFO>:QT_MESSAGELOGCONTEXT>
)

#Add the forms directory to the AUTOUIC search paths
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS} ${FORMS_DIR})

#add the executable
if(WIN32)
    add_executable(${PROJECT_NAME} WIN32
        main.cpp
        ${SOURCES}
    )
elseif(UNIX)
    add_executable(${PROJECT_NAME}
        main.cpp
        ${SOURCES}
    )
endif()

#Add the target includes for target
#target_include_directories(${PROJECT_NAME} PRIVATE ${FORMS_DIR})
#target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
#target_include_directories(${PROJECT_NAME} PRIVATE ${SOURCE_DIR})

#=======================Linking libraries=====================#
target_link_libraries(${PROJECT_NAME} PRIVATE 
    Qt6::Widgets
    Qt6::PrintSupport
)